#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

bool isprime(int n)
{
	if (n == 1) return false;
	else
	{
		for (int i = 2; i <= sqrt(n); i++)
		{
			if (n % i == 0)
				return false;
		}
	}
	return true;
}

void solve()
{
	int x, k;
	cin >> x >> k;
	if (x == 1 && k == 2)
	{
		cout << "YES" << endl;
		return;
	}
	if (isprime(x) && k == 1)
	{
		cout << "YES" << endl;
		return;
	}
	cout << "NO" << endl;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}